<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--创建字典数据模态框-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-verify">
    <div class="modal-dialog" style="width:500px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">审核配置信息</h4>
            </div>
            <div class="modal-body">
                <form id="verifyForm" class="form-horizontal">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label" for="verifyForm-name">名称</label>
                        <div class="col-sm-6">
                            <input id="verifyForm-name" type="text" class="form-control" name="name" placeholder="请输入名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-4 control-label" for="verifyForm-reportType">分类</label>
                        <div class="col-xs-6">
                            <select id="verifyForm-reportType" class="form-control" name="reportType">
                                <option th:each="type : ${repTypes}" th:value="${type.value}"
                                        th:text="${type.name}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-4 control-label" for="verifyForm-post">审核级别</label>
                        <div class="col-xs-6">
                            <select id="verifyForm-post" class="form-control" name="post">
                                <option th:each="post : ${posts}" th:value="${post.id}"
                                        th:text="${post.name}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label" for="verifyForm-orderNo">顺序</label>
                        <div class="col-sm-6">
                            <select id="verifyForm-orderNo" class="form-control" name="orderNo">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-4 control-label" for="verifyForm-comp">是否完结</label>
                        <div class="col-xs-6">
                            <select id="verifyForm-comp" class="form-control" name="comp">
                                <option value="1">是</option>
                                <option value="0" selected>否</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-4 control-label" for="verifyForm-status">是否启用</label>
                        <div class="col-xs-6">
                            <select id="verifyForm-status" class="form-control" name="status">
                                <option value="1" selected>是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" shiro:haspermission="basic:verify:edit" class="btn btn-info"
                        id="btn-create-verify">提交
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

<section class="content-header">
    <h1>审核配置</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="queryForm-reportType">分类</label>
                                    <select id="queryForm-reportType" class="form-control" name="reportType">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${repTypes}" th:value="${type.value}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                                <a href="javascript:void(0);" shiro:haspermission="basic:verify:edit"
                                   class="btn btn-info pull-right" onclick="openCreateVerifyModal()">
                                    <span class="Bold">添加</span>
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    var table;

    /** 打开创建数据模态框 */
    function openCreateVerifyModal() {
        js.modal.open("modal-verify");
    }

    /** 打开编辑数据模态框 */
    function openEditVerifyModal(result) {
        $("#verifyForm").fillData(result);
        js.modal.open("modal-verify");
        setTimeout(function () {
            js.validate.validing("verifyForm");
        }, 500);
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "basic/verify/list",
            columns: [
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: "名称", field: 'name'},
                {title: "分类", field: 'reportType',
                    formatter: function (value) {
                        if (value === 1) {
                            return '<span class="badge label-success">外购件</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">外协件</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-inverse">原材料</span>';
                        } else if (value === 4) {
                            return '<span class="badge label-info">工艺卡</span>';
                        }
                    }
                },
                {title: "审核级别", field: 'dictPostName'},
                {title: "顺序", field: 'orderNo'},
                {title: "完结", field: 'comp',
                    formatter: function (value) {
                        if (value === 1) {
                            return '<span class="badge label-success">是</span>';
                        } else if (value === 0) {
                            return '<span class="badge label-inverse">否</span>';
                        }
                    }
                },
                {title: "启用", field: 'status',
                    formatter: function (value) {
                        if (value === 1) {
                            return '<span class="badge label-success">是</span>';
                        } else if (value === 0) {
                            return '<span class="badge label-inverse">否</span>';
                        }
                    }
                },
                {
                    title: "操作",
                    width: '250',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (hasP('basic:verify:edit')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditVerifyModal(' + js.jsonStringify(row) + ')"> 编辑</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 初始化验证 */
        js.validate.init("verifyForm", {
            fields: {
                name: {validators: {notEmpty: {message: '请输入名称'}}},
                orderNo: {validators: {notEmpty: {message: '请输入顺序'}}}
            }
        });

        /** 创建或编辑 */
        $("#btn-create-verify").click(function () {
            var url = ctx + "basic/verify/save";
            if ($("#id").val()) {
                url = ctx + "basic/verify/update";
            }
            js.validSubmit({
                formId: "verifyForm",
                url: url,
                data: new FormData($("#verifyForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-verify");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

        /** 隐藏 modal-create-verify */
        js.modal.hideEvent("modal-verify", function () {
            js.validate.reset("verifyForm");
            js.reset("verifyForm");
        })
    });
</script>
</body>
</html>
